package jdbc;

import com.mysql.cj.jdbc.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class demo1 {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource=new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java118?characterEncoding=utf8&usrSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("admin");
        Connection connection=dataSource.getConnection();

        Scanner in=new Scanner(System.in);
        int id=in.nextInt();
        in.nextLine();
        String name=in.nextLine();
        String sql="insert into student values(?,?)";
        PreparedStatement statement=connection.prepareStatement(sql);
        statement.setInt(1,id);
        statement.setString(2,name);

        int n=statement.executeUpdate();
        System.out.println("n="+n);
        statement.close();
        connection.close();
    }
}
